{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0e960bb0",
   "metadata": {},
   "source": [
    "### Series数据结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "dc61214c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "bcbfdb06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int32"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建一维的带索引数据结构：pd.Series(data=None,index=None,dtype=None,name=None,copy=False,fastpath=False）\n",
    "\n",
    "sdata = pd.Series(np.arange(1,4),index = list('abc'))\n",
    "sdata"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ef6f3fc",
   "metadata": {},
   "source": [
    "### 查看下标对应的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "639728c6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# Series对象访问   .iloc[]:iloc是原下标，也就是默认值，计算机的记忆\n",
    "#loc是修改过的下标，我们把他叫作标签，标签是由我们自主给的，计算机并不会自己产生\n",
    "\n",
    "#默认数字索引\n",
    "print(sdata.iloc[0])\n",
    "#使用标签\n",
    "print(sdata['b'])\n",
    "#使用loc方式，只能使用标签\n",
    "print(sdata.loc['c'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "88f31a38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   -1.2\n",
       "1    3.7\n",
       "2    2.5\n",
       "3   -8.2\n",
       "4    6.3\n",
       "dtype: float64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series([-1.2,3.7,2.5,-8.2,6.3])\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "26c125d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a   -1.2\n",
       "b    3.7\n",
       "c    2.5\n",
       "d   -8.2\n",
       "e    6.3\n",
       "dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = pd.Series([-1.2,3.7,2.5,-8.2,6.3],index=list('abcde'))\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "8b5b2726",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RangeIndex(start=0, stop=5, step=1)\n",
      "[-1.2  3.7  2.5 -8.2  6.3]\n"
     ]
    }
   ],
   "source": [
    "print(s1.index)\n",
    "print(s1.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "1472e34d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.7"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3 = pd.Series([-1.2,3.7,2.5,-8.2,6.3],index=[5,4,3,2,1])\n",
    "s3.iloc[1]  #iloc是原下标，也就是默认值，计算机的记忆"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "c14d9c61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.3"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3.loc[1]#loc是修改过的下标，我们把他叫作标签，标签是由我们自主给的，计算机并不会自己产生"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff5fe532",
   "metadata": {},
   "source": [
    "### 创建对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "2ee1e341",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "小陈    93\n",
       "小张    91\n",
       "小曾    78\n",
       "小邓    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建对象\n",
    "s4 = pd.Series({\"小李\":82,\"小陈\":93,\"小张\":91,\"小曾\":78,\"小邓\":68})\n",
    "s4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "29a5581e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "小陈    93\n",
       "小张    95\n",
       "小曾    78\n",
       "小邓    68\n",
       "dtype: int64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#修改数据\n",
    "s4.loc[\"小张\"] = 95\n",
    "s4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "606b34e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    82\n",
       "dtype: int64"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#筛选数据\n",
    "s4[(s4 > 80) & (s4 < 90)]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66d9be79",
   "metadata": {},
   "source": [
    "### 四则运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "56814a54",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1      9.0\n",
       "2      NaN\n",
       "3     11.0\n",
       "5      5.0\n",
       "7      NaN\n",
       "9      NaN\n",
       "10     NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#四则运算\n",
    "a = pd.Series([1,4,2,3,5],index=[1,3,5,7,9])\n",
    "b = pd.Series([8,1,7,3,9],index=[1,2,3,5,10])\n",
    "a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "77d6eb84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1      9.0\n",
       "2      1.0\n",
       "3     11.0\n",
       "5      5.0\n",
       "7      3.0\n",
       "9      5.0\n",
       "10     9.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.add(b,fill_value = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "d99608b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    -7.0\n",
       "2    -1.0\n",
       "3    -3.0\n",
       "5    -1.0\n",
       "7     3.0\n",
       "9     5.0\n",
       "10   -9.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.sub(b,fill_value = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "f30f78ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1      8.0\n",
       "2      1.0\n",
       "3     28.0\n",
       "5      6.0\n",
       "7      3.0\n",
       "9      5.0\n",
       "10     9.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.mul(b,fill_value = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "da4a46d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1     0.125000\n",
       "2     1.000000\n",
       "3     0.571429\n",
       "5     0.666667\n",
       "7     3.000000\n",
       "9     5.000000\n",
       "10    0.111111\n",
       "dtype: float64"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.div(b,fill_value = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "5462e695",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "1\n",
      "15\n",
      "3.0\n"
     ]
    }
   ],
   "source": [
    "print(a.max())\n",
    "print(a.min())\n",
    "print(a.sum())\n",
    "print(a.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "c0dde507",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    5.000000\n",
       "mean     3.000000\n",
       "std      1.581139\n",
       "min      1.000000\n",
       "25%      2.000000\n",
       "50%      3.000000\n",
       "75%      4.000000\n",
       "max      5.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57a9d7b4",
   "metadata": {},
   "source": [
    "### apply判断数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "d6b63617",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "小李    B\n",
       "小陈    A\n",
       "小张    A\n",
       "小曾    C\n",
       "小邓    D\n",
       "dtype: object"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# apply()对数据批量处理\n",
    "def get_grade_from_score(score):\n",
    "    if score >= 90:\n",
    "        return \"A\"\n",
    "    if score >= 80:\n",
    "        return \"B\"\n",
    "    if score >= 70:\n",
    "        return \"C\"\n",
    "    else:\n",
    "        return \"D\"\n",
    "scores = pd.Series({\"小李\":82,\"小陈\":93,\"小张\":91,\"小曾\":78,\"小邓\":68})\n",
    "grades = scores.apply(get_grade_from_score)\n",
    "grades"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "4977b891",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>01</td>\n",
       "      <td>二班</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>02</td>\n",
       "      <td>一班</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>03</td>\n",
       "      <td>二班</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>04</td>\n",
       "      <td>三班</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>05</td>\n",
       "      <td>一班</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  班级  成绩\n",
       "0  01  二班  92\n",
       "1  02  一班  67\n",
       "2  03  二班  70\n",
       "3  04  三班  88\n",
       "4  05  一班  76"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# DataFrame创建二维数组\n",
    "s_id = pd.Series([\"01\",\"02\",\"03\",\"04\",\"05\"])\n",
    "s_class = pd.Series([\"二班\",\"一班\",\"二班\",\"三班\",\"一班\"])\n",
    "s_grade = pd.Series([92,67,70,88,76])\n",
    "\n",
    "df1 = pd.DataFrame({\"学号\":s_id,\"班级\":s_class,\"成绩\":s_grade})\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "b8dff181",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>小明</th>\n",
       "      <td>01</td>\n",
       "      <td>二班</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小红</th>\n",
       "      <td>02</td>\n",
       "      <td>一班</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小杰</th>\n",
       "      <td>03</td>\n",
       "      <td>二班</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小丽</th>\n",
       "      <td>04</td>\n",
       "      <td>三班</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>小华</th>\n",
       "      <td>05</td>\n",
       "      <td>一班</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    学号  班级  成绩\n",
       "小明  01  二班  92\n",
       "小红  02  一班  67\n",
       "小杰  03  二班  70\n",
       "小丽  04  三班  88\n",
       "小华  05  一班  76"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Index = [\"小明\",\"小红\",\"小杰\",\"小丽\",\"小华\"]\n",
    "s_id = pd.Series([\"01\",\"02\",\"03\",\"04\",\"05\"],index = Index )\n",
    "s_class = pd.Series([\"二班\",\"一班\",\"二班\",\"三班\",\"一班\"],index = Index)\n",
    "s_grade = pd.Series([92,67,70,88,76],index = Index)\n",
    "\n",
    "df1 = pd.DataFrame({\"学号\":s_id,\"班级\":s_class,\"成绩\":s_grade})\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77ff503e",
   "metadata": {},
   "source": [
    "### 标签"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "e0f94688",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['小明', '小红', '小杰', '小丽', '小华'], dtype='object')"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "35f1d136",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['学号', '班级', '成绩'], dtype='object')"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "cf77bc6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['01', '二班', 92],\n",
       "       ['02', '一班', 67],\n",
       "       ['03', '二班', 70],\n",
       "       ['04', '三班', 88],\n",
       "       ['05', '一班', 76]], dtype=object)"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "8b4e2333",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>学号</th>\n",
       "      <td>01</td>\n",
       "      <td>02</td>\n",
       "      <td>03</td>\n",
       "      <td>04</td>\n",
       "      <td>05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>班级</th>\n",
       "      <td>二班</td>\n",
       "      <td>一班</td>\n",
       "      <td>二班</td>\n",
       "      <td>三班</td>\n",
       "      <td>一班</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>成绩</th>\n",
       "      <td>92</td>\n",
       "      <td>67</td>\n",
       "      <td>70</td>\n",
       "      <td>88</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     0   1   2   3   4\n",
       "学号  01  02  03  04  05\n",
       "班级  二班  一班  二班  三班  一班\n",
       "成绩  92  67  70  88  76"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表转置\n",
    "df1.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "339fe28c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    二班\n",
       "1    一班\n",
       "2    二班\n",
       "3    三班\n",
       "4    一班\n",
       "Name: 班级, dtype: object"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#提取数据（列）\n",
    "df1[\"班级\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "35af9fd2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>01</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>02</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>03</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>04</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>05</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  成绩\n",
       "0  01  92\n",
       "1  02  67\n",
       "2  03  70\n",
       "3  04  88\n",
       "4  05  76"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1[[\"学号\",\"成绩\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "00af4dee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "学号    02\n",
       "班级    一班\n",
       "成绩    67\n",
       "Name: 1, dtype: object"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 提取数据（行）\n",
    "df1.loc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "da5f2803",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "学号    04\n",
       "班级    三班\n",
       "成绩    88\n",
       "Name: 3, dtype: object"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.iloc[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2dc88109",
   "metadata": {},
   "source": [
    "### 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "2f0c4265",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>02</td>\n",
       "      <td>一班</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>03</td>\n",
       "      <td>二班</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  班级  成绩\n",
       "1  02  一班  67\n",
       "2  03  二班  70"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.loc[1:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "7e2ad391",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>一班</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>二班</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   班级  成绩\n",
       "1  一班  67\n",
       "2  二班  70"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 行列切片\n",
    "df1.loc[1:2,\"班级\":\"成绩\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "afa0736e",
   "metadata": {},
   "source": [
    "### 筛选"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "de123aa3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     True\n",
       "1    False\n",
       "2    False\n",
       "3     True\n",
       "4    False\n",
       "Name: 成绩, dtype: bool"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1[\"成绩\"] > 80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "754315b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>01</td>\n",
       "      <td>二班</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>04</td>\n",
       "      <td>三班</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  班级  成绩\n",
       "0  01  二班  92\n",
       "3  04  三班  88"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1[df1[\"成绩\"] > 80]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f19d25b9",
   "metadata": {},
   "source": [
    "### 查看前几行数据-数据量大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "177c8761",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>班级</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>01</td>\n",
       "      <td>二班</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>02</td>\n",
       "      <td>一班</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  班级  成绩\n",
       "0  01  二班  92\n",
       "1  02  一班  67"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.head(2)   #输出前两行数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4213a8b7",
   "metadata": {},
   "source": [
    "### drop搭配axis用法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "97e5d8c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试2</th>\n",
       "      <th>考试3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>小1</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002</th>\n",
       "      <td>小2</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>小3</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>004</th>\n",
       "      <td>小4</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>小5</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>小6</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 考试1 考试2 考试3\n",
       "001  小1  85  95  92\n",
       "002  小2  85  95  92\n",
       "003  小3  85  95  92\n",
       "004  小4  85  95  92\n",
       "005  小5  85  95  92\n",
       "006  小6  85  95  92"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student_data = {\n",
    "    \"001\":{\"姓名\":\"小1\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "    \"002\":{\"姓名\":\"小2\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "    \"003\":{\"姓名\":\"小3\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "    \"004\":{\"姓名\":\"小4\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "    \"005\":{\"姓名\":\"小5\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "    \"006\":{\"姓名\":\"小6\",\"考试1\":85,\"考试2\":95,\"考试3\":92},\n",
    "}\n",
    "student = pd.DataFrame(student_data).T\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "1f3481a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试2</th>\n",
       "      <th>考试3</th>\n",
       "      <th>考试4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>小1</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002</th>\n",
       "      <td>小2</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>小3</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>004</th>\n",
       "      <td>小4</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>小5</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>小6</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>007</th>\n",
       "      <td>小7</td>\n",
       "      <td>90</td>\n",
       "      <td>85</td>\n",
       "      <td>65</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 考试1 考试2 考试3  考试4\n",
       "001  小1  85  95  92   72\n",
       "002  小2  85  95  92   69\n",
       "003  小3  85  95  92   79\n",
       "004  小4  85  95  92   83\n",
       "005  小5  85  95  92   82\n",
       "006  小6  85  95  92   76\n",
       "007  小7  90  85  65   75"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student[\"考试4\"] = pd.Series([72,69,79,83,82,76],index = [\"001\",\"002\",\"003\",\"004\",\"005\",\"006\"])\n",
    "student.loc[\"007\"] = [\"小7\",90,85,65,75]\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "b707bd4a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试2</th>\n",
       "      <th>考试3</th>\n",
       "      <th>考试4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>小1</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>小3</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>小5</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>小6</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 考试1 考试2 考试3  考试4\n",
       "001  小1  85  95  92   72\n",
       "003  小3  85  95  92   79\n",
       "005  小5  85  95  92   82\n",
       "006  小6  85  95  92   76"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#drop:删除\n",
    "#axis:指定行列\n",
    "student.drop([\"002\",\"004\"],axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "35c11440",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>小1</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002</th>\n",
       "      <td>小2</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>小3</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>004</th>\n",
       "      <td>小4</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>小5</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>小6</td>\n",
       "      <td>85</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 考试1 考试3\n",
       "001  小1  85  92\n",
       "002  小2  85  92\n",
       "003  小3  85  92\n",
       "004  小4  85  92\n",
       "005  小5  85  92\n",
       "006  小6  85  92"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student.drop([\"考试2\",\"考试4\"],axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "834a2aad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     姓名 考试1 考试2 考试3  考试4\n",
      "007  小7  90  85  65   75\n"
     ]
    }
   ],
   "source": [
    "print(student.tail(1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0577cbe7",
   "metadata": {},
   "source": [
    "### 两个数据相加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "6c984caa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试2</th>\n",
       "      <th>考试3</th>\n",
       "      <th>考试4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>004</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "      <td>94</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>007</th>\n",
       "      <td>92</td>\n",
       "      <td>88</td>\n",
       "      <td>67</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    考试1 考试2 考试3  考试4\n",
       "001  87  98  94   77\n",
       "002  87  98  94   74\n",
       "003  87  98  94   84\n",
       "004  87  98  94   88\n",
       "005  87  98  94   87\n",
       "006  87  98  94   81\n",
       "007  92  88  67   80"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bonus = pd.Series({\"考试1\":2,\"考试2\":3,\"考试3\":2,\"考试4\":5})\n",
    "bonus + student[[\"考试1\",\"考试2\",\"考试3\",\"考试4\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae2d81a6",
   "metadata": {},
   "source": [
    "### 重新赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "95cca012",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>考试1</th>\n",
       "      <th>考试2</th>\n",
       "      <th>考试3</th>\n",
       "      <th>考试4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>001</th>\n",
       "      <td>小1</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>002</th>\n",
       "      <td>小2</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>003</th>\n",
       "      <td>小3</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>004</th>\n",
       "      <td>小4</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>005</th>\n",
       "      <td>小5</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>006</th>\n",
       "      <td>小6</td>\n",
       "      <td>85</td>\n",
       "      <td>95</td>\n",
       "      <td>92</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>007</th>\n",
       "      <td>小7</td>\n",
       "      <td>90</td>\n",
       "      <td>85</td>\n",
       "      <td>65</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 考试1 考试2 考试3  考试4\n",
       "001  小1  85  95  92   82\n",
       "002  小2  85  95  92   79\n",
       "003  小3  85  95  92   89\n",
       "004  小4  85  95  92   93\n",
       "005  小5  85  95  92   92\n",
       "006  小6  85  95  92   86\n",
       "007  小7  90  85  65   85"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student[\"考试4\"] = student[\"考试4\"] + 10\n",
    "student"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "d263668c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "001    90.666667\n",
       "002    90.666667\n",
       "003    90.666667\n",
       "004    90.666667\n",
       "005    90.666667\n",
       "006    90.666667\n",
       "dtype: float64"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "average = student.loc[\"001\":\"006\",\"考试1\":\"考试3\"].mean(axis=1)\n",
    "average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b56e09d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
